import api from '../../common/api';
var countdown = 60;
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShow: true,//获取验证码按钮显示
    lastTime: '',//倒计时
    phoneNumer: "",//手机号
    verificationCode:''


  },
  //获取手机号
  getPhoneNumer(e){
    this.setData({
      phoneNumer: e.detail.value
    })
  },
  //获取验证码
  getCode() {
    const that = this;
    api.regSendVerifyCode({ mp: that.data.phoneNumer }, res => {
      that.settime();
    })
  },
  //输入验证码
  getVerificationCode(e) {
    this.setData({
      verificationCode: e.detail.value
    })
  },
  //登录
  login(){
    const that = this;
    api.register({ mp: that.data.phoneNumer, verifyCode: that.data.verificationCode, appName:"jjr"},res => {
      getApp().assignSession({mobile: that.data.phoneNumer})
      that.goIndex();
    })
  },
  //跳转首页
  goIndex() {
    app.appGotoNextPage()
  },
//验证码倒计时
  settime: function () {
    var that = this;
    if (countdown == 0) {
      that.setData({
        isShow: true
      })
      countdown = 60;
      return;
    } else {
      that.setData({
        isShow: false,
        lastTime: countdown
      })
      countdown--;
    }
    setTimeout(that.settime, 1000)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})